package com.person.webdemoproject2.mapper;

import com.person.webdemoproject2.pojo.Collections;
import com.person.webdemoproject2.pojo.Like_statue;
import com.person.webdemoproject2.pojo.Post;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;

@Mapper
public interface PostMapper {

    @Update("update tb_post SET `like`=`like`+1 where id=#{postId}")
    void likePost(int postId);
    @Select("select tb_post.`like` from tb_post where id=#{postId}")
    int getLikeCount(int postId);
    @Insert("insert into tb_collection (userid, postid, create_time, update_time) VALUES (#{userid},#{postid},#{create_time},#{update_time})")
    void collectPost(Collections collections);
    @Select("select count(*) from tb_collection where userid=#{userid} AND postid=#{postid}")
    Integer checkcollect(Integer userid,Integer postid);

    @Select("select count(*) from tb_like where postid=#{postId} AND userid=#{userId}")
    Integer check_like(int postId, Integer userId);

    @Insert("insert into tb_like (userid, postid,statue, create_time, update_time) VALUES (#{userid},#{otherid},#{statue},#{create_time},#{update_time}) ")
    void create_like(Like_statue likeStatue);
    @Select("select statue from tb_like where userid=#{userId} AND postid=#{postId}")
    Integer check_statue(int postId, Integer userId);
    @Update("update tb_like SET statue=#{statue},update_time=#{updateTime} where postid=#{postId} AND userid=#{userId}")
    void updateStatue(int postId, Integer userId, Integer statue, LocalDateTime updateTime);
    @Update("update tb_post SET `like`=`like`-1 where id=#{postId}")
    void _likePost(int postId);
    @Select("select likes from tb_comment where id=#{commentId}")
    int getLikeComment(Integer commentId);
    @Insert("insert into tb_likecomment (userid, statue, comment_id, create_time, update_time) VALUES (#{userid},#{statue},#{otherid},#{create_time},#{update_time}) ")
    void create_likec(Like_statue likeStatue);
    @Update("update tb_comment SET likes=likes+1 where id=#{commentId}")
    void likeComment(Integer commentId);
    @Select("select statue from tb_likecomment where comment_id=#{commentId} AND userid=#{userId}")
    Integer check_cstatue(Integer commentId, Integer userId);
    @Update("update tb_likecomment SET statue=#{statue},update_time=#{updateTime} where userid=#{userId} AND comment_id=#{commentId}")
    void updatecStatue(Integer commentId, Integer userId, Integer statue, LocalDateTime updateTime);
    @Update("update tb_comment SET likes=likes-1 where id=#{commentId}")
    void _likeComment(Integer commentId);
    @Select("select count(*) from tb_likecomment where comment_id=#{commentId} AND userid=#{userId}")
    Integer check_clike(Integer commentId, Integer userId);
    @Select("select userid from tb_post where id=#{postId}")
    Integer findSender(int postId);
    @Select("select userid from tb_comment where id=#{commentId}")
    Integer findCommenter(Integer commentId);

    void updatePost(Post post);
    @Select("select count(*) from tb_post where userid=#{userId} AND id=#{postId}")
    Integer check_user(Integer userId, Integer postId);
}
